#include "connectionwindow.h"
#include <QGridLayout>
#include <QMessageBox>
#include <QIntValidator>

#include <QDebug>

ConnectionWindow::ConnectionWindow(QWidget *parent, QString ip, int port, QString addr) :
    QDialog(parent)
{
    iplbl = new QLabel("IP: ", this);
    ipedit = new QLineEdit(ip, this);
    ipedit->setInputMask("000.000.000.000");

    portlbl = new QLabel("Port: ", this);
    portedit = new QLineEdit(this);
    portedit->setText(QString("%1").arg(port));
    portedit->setValidator(new QIntValidator(this));

    addrlbl = new QLabel("Addr: ", this);
    addredit = new QLineEdit(this);
    addredit->setText(QString("%1").arg(addr));

    buttonbox = new QDialogButtonBox(
            QDialogButtonBox::Ok|QDialogButtonBox::Cancel, Qt::Horizontal, this);

    QGridLayout* mainLayout = new QGridLayout;
    mainLayout->addWidget(iplbl, 0, 0);
    mainLayout->addWidget(ipedit, 0, 1, Qt::AlignLeft);
    mainLayout->addWidget(portlbl, 1, 0);
    mainLayout->addWidget(portedit, 1, 1, Qt::AlignLeft);
    mainLayout->addWidget(addrlbl, 2, 0);
    mainLayout->addWidget(addredit, 2, 1, Qt::AlignLeft);
    mainLayout->addWidget(buttonbox, 3, 0, 1, 2, Qt::AlignCenter);

    this->setLayout(mainLayout);

    connect(buttonbox, SIGNAL(accepted()), this, SLOT(accept()));
    connect(buttonbox, SIGNAL(rejected()), this, SLOT(reject()));
}

QString ConnectionWindow::getIP()
{
    return ipedit->text();
}

QString ConnectionWindow::getAddr()
{
    return addredit->text();
}

int ConnectionWindow::getPort()
{
    return portedit->text().toInt();
}
